package edu.uvic.TabViz.framework.WiFi;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import android.util.Log;

public class Protocol {
	public static final int STATUS_WAITING   = 10; 
	public static final int STATUS_GRAB      = 11;
	public static final int STATUS_READY 	= 12;
	public static final int STATUS_SHARE 	= 14;


	public static final int SYNC          = 100;
	public static final int REPLICATE     = 200;
	public static final int SHARE         = 300;
	public static final int GRAB          = 400;
	public static final int RELEASE       = 500;

	protected int state = STATUS_WAITING;

	protected Data lastMsg = new Data(new Object(),0);

	public static Data getData( ObjectInputStream oIn ) throws IOException{
		Data  tDataFromClient = null;         
		while ( tDataFromClient == null )
			try {
				tDataFromClient = (Data) oIn.readObject();
			} catch ( ClassNotFoundException e ) {
				Log.e("edu.uvic.TabViz","Protocole",e);
			}
		return tDataFromClient;
	} 

	public static void sendData( Data tDataToClient, ObjectOutputStream  oOut ) throws IOException{  
		oOut.writeObject( tDataToClient );
		oOut.flush();
		return;
	}

	public boolean isReady(){
		if(state == STATUS_READY)
			return true;
		else return false;
	}

	public void setState(int state) {
		this.state = state;
	}
	
	
}
